package com.sservice.banfu.service.impl;

import com.sservice.banfu.mapper.DeviceMapper;
import com.sservice.banfu.e.Device;
import com.sservice.banfu.service.DeviceService;
import com.sservice.banfu.vo.DeviceVo;
import com.sservice.base.entity.dto.ListResult;
import com.sservice.base.entity.dto.Pagination;
import com.sservice.generator.service.AbstractService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created by byte_su@163.com on 2018/01/12.
 */
@Service
public class DeviceServiceImpl extends AbstractService<Device> implements DeviceService {

    @Autowired
    private DeviceMapper deviceMapper;

    @Override
    public List<Device> queryByPage(Device user) {
        Example example = new Example(Device.class);
        example.createCriteria()
                .andEqualTo("type1", user.getType1())
                .andLike("name", user.getName())
                .andEqualTo("creatorId", user.getCreatorId());
        return deviceMapper.selectByExample(example);
    }

    @Override
    public int queryCount(Device user) {
        Example example = new Example(Device.class);
        example.createCriteria()
                .andEqualTo("type1", user.getType1())
                .andEqualTo("name", user.getName());
        return deviceMapper.selectCountByExample(example);
    }

    @Override
    public ListResult page(DeviceVo user) {
        List<DeviceVo> list = deviceMapper.query(user);
        ListResult listResult = new ListResult(true, list);
        Pagination pagination = new Pagination(user.getPage(), deviceMapper.count(user), user.getSize());
        listResult.setPage(pagination);
        return listResult;
    }
}
